https://leetcode.cn/problems/flood-fill/description/
class Solution {
public:
    typedef pair<int, int> PII;
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc,
                                  int color) {
        if (image[sr][sc] == color)
            return image;
        int prev = image[sr][sc];
        int n = image.size(), m = image[0].size();
        queue<PII> q;
        q.push({sr, sc});
        while (!q.empty()) {
            auto [a, b] = q.front();
            image[a][b] = color;
            q.pop();
            for (int i = 0; i < 4; i++) {

                int x = a + dx[i], y = b + dy[i];
                // 相同就入队列，扩展下一层
                if (x >= 0 && x < n && y >= 0 && y < m && image[x][y] == prev) {
                    q.push({x, y});
                }
            }
        }
        return image;
    }
};